/**
 * @file 	SHT30.h
 * @author 	彬_Linus (you@domain.com)
 * @brief 	基于 cd-your_heart 的 SHT30使用的学习过程2 SHT30驱动程序 修改
 * 			CSDN : https://blog.csdn.net/qq_14823403/article/details/83185489
 * 			此组件仅适用于ESP-IDF
 * 			需要My_i2c组件支持
 * 			支持SHT30,GXHT30
 * 
 * @brief 	based on SHT30使用的学习过程2 SHT30驱动程序 by cd-your_heart
 *        	CSDN : https://blog.csdn.net/qq_14823403/article/details/83185489
 *        	This component only supports ESP-IDF
 *        	This component requires a component named My_i2c
 * @version 1.0
 * @date 2022-03-08
 * 
 * @copyright Copyright (c) 2022
 * 
 */


#pragma once

#include <stdio.h>
#include "stdlib.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "My_i2c.h"


#define DEV_SHT30_ADDRESS       (uint8_t)0x44		/*!< SHT30 I2C Address 		*** SHT30地址 */
#define DEV_SHT30_SCL_NUM       2			/*!< gpio number for SCL 	*** SCL的IO口*/
#define DEV_SHT30_SDA_NUM       3			/*!< gpio number for SDA 	*** SDA的IO口 */
#define DEV_SHT30_I2C_NUM       (i2c_port_t)0			/*!< I2C port number  		*** I2C编号*/


typedef enum {
	SHT3XD_REPEATABILITY_HIGH,
	SHT3XD_REPEATABILITY_MEDIUM,
	SHT3XD_REPEATABILITY_LOW,
} SHT31D_Repeatability;

typedef enum {
	SHT3XD_MODE_CLOCK_STRETCH,
	SHT3XD_MODE_POLLING,
} SHT31D_Mode;

typedef enum {
	SHT3XD_FREQUENCY_HZ5,
	SHT3XD_FREQUENCY_1HZ,
	SHT3XD_FREQUENCY_2HZ,
	SHT3XD_FREQUENCY_4HZ,
	SHT3XD_FREQUENCY_10HZ
} SHT31D_Frequency;



class SHT30_DEVICE{
    public:

		SHT30_DEVICE(uint8_t add,i2c_port_t i2c_num):_address(add),_i2c_num(i2c_num){}
        void begin(uint8_t address,i2c_port_t i2c_num);
        void Reset();

        esp_err_t periodicStart(SHT31D_Repeatability repeatability, SHT31D_Frequency frequency);
		esp_err_t periodReadData();
		esp_err_t ReadTempeHumi();

		float Temp;
		float Humi;


    private:
        uint8_t _address;
        i2c_port_t _i2c_num;
};

